package startTest;

import fundamental.*;

import java.util.ArrayList;
import java.util.Comparator;

import static initialization.ProblemLoad.*;
import static initialization.InitialFunction.*;
import static localSearch.LocalSearch.*;
import static fundamental.Params.*;
import static perturbation.Perturb.*;


public class Test1 {
    public static void main(String[] args) {
        long start = System.currentTimeMillis();
        int num = 238;
        String s = "9_"+num+".txt";
        readBenchMark("聚类后的数据2021_10/聚类后客户需求信息"+s,"聚类后的数据2021_10/聚类后距离矩阵"+s, num);
        H2getIniSol();
        System.out.println("open="+openedCandSet.size());
        //Check.checkVehicle1();
        //Check.check2();
        NS();
        getBetter = false;
        record.add(lsObj.cost);
        giantTSP = new GiantTSP(cap1, cap2);
        int iter = 0;
        long e1 = System.currentTimeMillis();
        while (perturbNImp < maxIter && (double)(e1 - start)/1000 < maxTime) {
            if (custNum == 1) break;
            System.out.println("第"+iter+"次扰动-->当前最优解为："+ lsObj.cost);
            perturb1();
            NS();
            if (getBetter) {
                giantTSP = new GiantTSP(cap1,cap2);
                System.out.println("改进了");
                getBetter = false;
            }else {
                giantTSP.resetTour();
                System.out.println("未改进");
                for (Cand cand: openedCandSet
                     ) {
                    cand.initial();
                }
                openedCandSet.clear();
                openedCandSet.addAll(giantTSP.openedCandBase);
            }
            /*ArrayList<Cand> temp = new ArrayList<>(openedCandSet);
            temp.sort(Comparator.comparingInt(c -> c.num));
            System.out.println("openCansSet="+temp);
            ArrayList<Cand> temp1 = new ArrayList<>(giantTSP.openedCandBase);
            temp1.sort(Comparator.comparingInt(c -> c.num));
            System.out.println("baseOpened="+temp1);*/
            record.add(lsObj.cost);
            e1 = System.currentTimeMillis();
            iter++;
        }
        System.out.println(record);
        long end = System.currentTimeMillis();
        Check.checkBestCost();
        System.out.println("time spends = "+(double)(end-start)/1000);
        System.out.println("cost = "+lsObj.cost);
        //saveTxt();
    }
}
